<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>会员资料</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10" />

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/matrix-style.css" />
<link rel="stylesheet" href="css/matrix-media.css" />
<link rel="stylesheet" href="jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" href="jquery-easyui/themes/default/easyui.css" />
<link rel="stylesheet" href="jquery-easyui/themes/icon.css" />
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
<script charset="utf-8" src="editor/kindeditor-all.js"></script>
<script charset="utf-8" src="editor/lang/zh-CN.js"></script>
<link type="text/javascript" href="editor/themes/default/default.css"></link>
<script type="text/javascript" src="editor/plugins/code/prettify.js"></script>

<style>
 .content-header{
/*   margin-top:-38px;
 */  font-size:16px;
  background-color:#fff;
 }
 .content-header table{
  font-weight:bolder;
  margin-left:30px;
 }
 .content-header .header-number{
  margin-left:10px;
 }
 .widget-box .widget-content  td{
  text-align:center;
 }
 /*easyui*/
#fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
} 
</style>
<script>
function logout(){
		$.messager.confirm('Confirm','Are you sure you want to logout?',function(r){
            if (r){
                $.post('<%=request.getContextPath()%>/logout',function(result) {
					if (result.success) {
						$.messager.show({ // show error message
							title : '提示',
							msg : '退出成功'
						});
			           }
				 else {
						$.messager.show({ // show error message
									title : '提示',
									msg : '登录已过期，重新登录'
								});
					   }
				}, 'json');
    			window.open('<%=request.getContextPath()%>/index.jsp','_self');

		     }
	});
}
function profile(){
	window.open('<%=request.getContextPath()%>/profile?method=page','_self');
}
function gohome(){
	window.open('<%=request.getContextPath()%>/dashboard','_self');
}
</script>
<script type="text/javascript">
$(document).ready(function(){

	$.ajax({
		url:"<%=request.getContextPath()%>/task?method=taskcount",
		dataType:'json',
		type:'post',
		data:{},
		beforeSend:function(){
			
		},
		success:function(result){
			if(result.success){
				$("#count").text(result.count);
			}
		}
	})
	$('#dg').datagrid({
		    title:'会员总列表',
	        width:'100%',
		    pagination:true,
		    rownumbers:true,
		    fitColumns:true,
		    singleSelect:false,
		    idField:'uid',
		    checkOnSelect:false,
		    url:'<%=request.getContextPath()%>/member?method=total',
		    columns:[[
   		        {field:'ck',checkbox:true},
		        {field:'uid',title:'编号',width:"20%",
	              styler:function(value,row,index){
/* 			        		return ' cursor:pointer';
*/			        },
		    		formatter:function(value,row,index){
		       			return '<a href="#" title="点击可查看会员详情" onclick="readUser('+index+')">'+value+'</a>';
		    			
		    		}
    		    },
		        {field:'name',title:'姓名',width:'20%' 
		        },
		        {field:'school',title:'学校',width:'20%'},
		        {field:'grade',title:'年级',width:"20%",
			     formatter:function(value,row,index){
			    	switch (row.grade) {
					case 1:
						return '大一';
						break;
					case 2:
						return '大二';
						break;
					case 3:
						return '大三';
						break;
					case 4:
						return '大四';
						break;

					default:
						return '(空)';
						break;
					}
			     }
		        },
		        {field:'due',title:'到期时间',width:'20%' },
		        {field:'phone',title:'手机号',hidden:true},
		        {field:'email',title:'邮箱',hidden:true},
		        {field:'openid',title:'openid',hidden:true},
		        {field:'type',title:'会员类型',hidden:true},
		        {field:'assistid',title:'助理',hidden:true}
		    ]],
			 onClickRow: function (index, row) {//点击事件
					$("#dg2").datagrid({
						url:'<%=request.getContextPath()%>/member?method=backlist&id='+row.uid
					})
		     } ,
		     onLoadSuccess:function(index,row){
		    	 var s= $("#dg").datagrid('getPanel');
		    	 var rows = s.find('tr.datagrid-row');
		    	 var rows1 = s.find('tr.datagrid-row td[field!=ck]');
		    	 rows1.unbind('click').bind('click',function(e){
		    	   return false;
		      });
		     }
		});
	//header menu
var ddlMenu1 = $('#li1').menubutton({ menu: '#cusmenu1' }); 
var ddlMenu2 = $('#li2').menubutton({ menu: '#cusmenu2' }); 

//menubutton 依赖于 menu、linkbutton 这两个插件，所以我们可以这样搞定她
$(ddlMenu1.menubutton('options').menu).menu({
            onClick: function (item) {
            	if(item.id=='id1'){
            		
            	}else if(item.id=='id2'){
                    window.open("<%=request.getContextPath()%>/task?method=assisttasks","_blank")

            	}else if(item.id=='id3'){
                    window.open("<%=request.getContextPath()%>/","_self")
            	}
            }
	})
	$(ddlMenu2.menubutton('options').menu).menu({
	            onClick: function (item) {
	            	 if(item.id=='id4'){
	            	}
	            }
	})
	
});
</script>
<script>
function vip(){
	$("#dg").datagrid({
		url:"<%=request.getContextPath()%>/member?method=vip"
	})
}
function ordinary(){
	$("#dg").datagrid({
		url:"<%=request.getContextPath()%>/member?method=ordinary"
				
	
	})

}
function total(){
	$("#dg").datagrid({
		url:"<%=request.getContextPath()%>/member?method=total"
	})

}
function newBackup(){
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length==1){
		  $('#dlg').dialog('open').dialog('setTitle','添加备注');
		    $("#fm").form("load",rows[0]);
		  url='<%=request.getContextPath()%>/member?method=backadd&uid='+rows[0].uid;
	}else if(rows.length>1){
		 $.messager.show({
             title: 'Error',
             msg: "不能同时选中多个会员进行备份，一次选中一个"
         });
	}
}
function doadd(){
	$('#fm').form('submit',{
        url: url,
        onSubmit: function(){
        	   if(!$(this).form('validate')){
        		   alert("false");
              	 return false;
               }
        	   return true;
        },
        success: function(result){
            var result = eval('('+result+')');
            if (!result.success){
                $.messager.show({
                    title: 'Error',
                    msg: "添加失败"
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $.messager.show({
                    title: 'success',
                    msg: "添加备注成功"
                });
            }
        }
    });
}
function backdelete(id){
	$.messager.confirm('Confirm','Are you sure you want to delete?',function(r){
        if (r){
            $.post('<%=request.getContextPath()%>/member?method=backdelete&id='+id,function(result) {
				if (result.success) {
					$.messager.show({ // show error message
						title : '提示',
						msg : '删除成功'
					});
					$("#dg2").datagrid('reload');
		           }
			 else {
					$.messager.show({ // show error message
							title : '提示',
							msg : '删除失败'
						});
				   }
			}, 'json');

	     }
});
}
function backedit(index){
	$("#dg2").datagrid('selectRow', index);
	var row=$("#dg2").datagrid("getSelected");
	$("#dlg3").dialog('open').dialog('setTitle','修改备注');
	$("#fm3").form('load',row); 
	url="<%=request.getContextPath()%>/member?method=backedit&id="+row.id;
}
function doupdate(){
	$("#fm3").form("submit",{
		url:url,
		onSubmit:function(){
			
		},
		success:function(result){
            var result = eval('('+result+')');
			if(result.success){
				$.messager.show({
					title:'success',
					msg:'修改备注成功'
				})
				$("#dlg3").dialog('close')
				$("#dg2").datagrid('reload');
			}else{
				$.messager.show({
					title:'Error',
					msg:'编辑失败'
				})
			}
			
		}
	})
}
function showBackup(){
	var rows = $('#dg').datagrid('getSelections');
	if(rows.length==1){
		  $('#dlg2').dialog('open').dialog('setTitle','查看编辑备注');
		  $('#dg2').datagrid({
			    width:'100%',
			    pagination:true,
			    rownumbers:true,
			    fitColumns:true,
			    singleSelect:true,
			    idField:'id',
			    url:'<%=request.getContextPath()%>/member?method=backlist&uid='+rows[0].uid,
			    columns:[[
			        {field:'id',title:'编号'},
			        {field:'content',title:'内容' },
			        {field:'datetime',title:'日期时间'},
			        {field:'do',title:'操作',width:70,align:'center',
			            formatter:function(value,row,index){
			                if (true){
			                    var q = '<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="backedit('+index+')">编辑</a>  ';
			                    var z = '<a href="#" class="easyui-linkbutton"  onclick="backdelete('+row.id+')">删除</a>  ';
			                    return q+z;
			                } else {
			                    var e = '<a href="#" onclick="editrow('+index+')">Edit</a> ';
			                    var d = '<a href="#" onclick="deleterow('+index+')">Delete</a>';
			                    return e+d;
			                }
			            }
			        }
			    ]],
			});
	}else if(rows.length>1){
		 $.messager.show({
             title: 'Error',
             msg: "一次只能选中一个"
         });
	}
}

function readUser(index){
	 var rows=$("#dg").datagrid("getRows");
		$('#dlg4').dialog('open').dialog('setTitle','查看用户详情');
		$("#uid").text(rows[index].uid);
		$('#name').text(rows[index].name);
		$("#type").text(function(){
			switch (rows[index].type) {
			case 1:
				return '普通会员';
				break;
			case 2:
				return 'vip会员'
				break;
			default:
				break;
			}
		});
		$("#phone").text(rows[index].phone);
		$("#email").text(rows[index].email);
		$('#school').text(rows[index].school);
		$("#grade").text(function(){
			switch (rows[index].grade) {
			case 1:
				return '大一';
				break;
			case 2:
				return '大二';
				break;
			case 3:
				return '大三';
				break;
			case 4:
				return '大四';
				break;
			default:
				break;
			}
		});
		$("#due").text(rows[index].due);
		$("#assistid").text(rows[index].assistid);
		
}

function sendEmail(){
	var rows=$("#dg").datagrid('getSelections');
	if(rows.length>0){
		var item=[];
		for(var i=0;i<rows.length;i++){
			item.push(rows[i].email);
		}
		$('#to').textbox('setValue', item.toString());
		$("#dlg5").dialog('open').dialog('setTitle','邮件发送');
		 KindEditor.create("#editor_id",{
			 cssPath:'editor/plugins/code/prettify.css',
	 		 resize:0,
			 uploadJson:'editor/jsp/upload_json.jsp',
		     fileManagerJson : 'editor/jsp/file_manager_json.jsp',
			 allowPreviewEmoticons:true,
			 allowImageUpload:true,			
			 width:'100%',
			 afterBlur:function() {
			      this.sync();
			  }
			 }) ;
			url="<%=request.getContextPath()%>/member?method=email";
	}
}
function send(){
	$("#fm5").form('submit',{
		url:url,
		onSubmit:function(){
			
		},
		success:function(result){
            var result = eval('('+result+')');
			if(result.success){
				$.messager.show({
					title:'success',
					msg:'邮件发送成功'
				})
				$("#dlg5").dialog('close')
			}else{
				$.messager.show({
					title:'Error',
					msg:'邮件发送失败'
				})
			}
		}
	})
}
function showhistory(){
	var rows=$("#dg").datagrid('getSelections');
	if(rows.length==1){
		$("#dlg6").dialog("open").dialog('setTitle','活动历史');
		$("#dg3").datagrid({
			 width:'100%',
			    pagination:true,
			    rownumbers:true,
			    fitColumns:true,
			    singleSelect:true,
			    idField:'id',
			    url:'<%=request.getContextPath()%>/member?method=travels&uid='+rows[0].uid,
			    columns:[[
			        {field:'id',title:'活动编号'},
			        {field:'title',title:'标题'},
			        {field:'content',title:'活动内容',hidden:true},
			        {field:'datetime',title:'活动日期'},
			        {field:'money',title:'收费方式',
						formatter:function(value,row,index){
			                if (value==0){
			                   return '免费';
			                } else {
			                    return value;
			                }
					    }
						     
			        },

			    ]],
		})
		
	}else if(rows.length>1){
		$.messager.show({
			title:'error',
			msg:'一次只能选中一个'
		})
	}
}
</script>

</head>
<body>

<!--Header-part-->
<div id="header">
  <h1><a href="dashboard.html">Matrix Admin</a></h1>
</div>
<!--close-Header-part--> 

<!-- header menu -->
<ul style="position:absolute;left:200px;top:20px;list-style:none;">
 <li id="li2" style="float:left;padding:5px;color:#0094ff;font-size:12px;" icon="icon-lightning" onclick="gohome()">首页</li>
</ul>

<!-- header menu -->
<!-- header menu -->
<div id="welcome" >
<h3 style="position:absolute;top:5px;right:30px;font-size:16px;height:35px;line-height:32px;background:white;border-radius:10px 10px">
<a href="#"><span style="padding:5px;border-radius:10px 10px ;color:white;background:red;" id="count"></span></a>

<a href="#" class="easyui-menubutton" data-options="menu:'#mm5',iconCls:'icon-man'" style="color:#0094ff;">${sessionScope.assist.id }</a>
</h3>
</div>
<div id="mm5" style="width:150px;">
		<div data-options="iconCls:'icon-undo'" onclick="profile()">个人设置</div>
		<div class="menu-sep"></div>
		<div>我的任务</div>
		<div class="menu-sep"></div>
		<div>系统消息</div>
		<div class="menu-sep"></div>
		<div onclick="logout()">安全退出</div>
</div>
<!-- side bar start -->
<div id="sidebar" >
  <ul>
    <li  ><a  href="<%=request.getContextPath()%>/dashboard"><i class="icon icon-home"></i> <span>Dashboard控制面板</span></a> </li>
    <li> <a href="<%=request.getContextPath()%>/study?method=page"><i class="icon icon-signal"></i> <span>Study news留学信息</span></a> </li>
    <li> <a href="<%=request.getContextPath()%>/travel?method=page"><i class="icon icon-inbox"></i> <span>Travel New活动信息</span></a> </li>
    <li><a href="<%=request.getContextPath()%>/news?method=page"><i class="icon icon-th"></i> <span>Recent News近期新闻</span></a></li>
    <li class="active"><a href="<%=request.getContextPath()%>/member?method=page"><i class="icon icon-fullscreen"></i> <span>Members centre会员中心</span></a></li>
    <c:choose>
     <c:when test="${sessionScope.assist.type eq 0}">
      <li><a href="<%=request.getContextPath() %>/assist"><i class="icon icon-th-list"></i> <span>助理管理</span></a></li>
     </c:when>
    </c:choose>
      <li><a href="<%=request.getContextPath() %>/task"><i class="icon icon-th-list"></i> <span>任务管理</span></a></li>
  </ul>
</div>

<div id="content"  >
   
        <div class="easyui-layout" style="width:100%;height:100%;">
		<div region="center" 
			style="padding: 0px; background: #eee;">
			
</div>
</div>
</div>

<!--Footer-part-->
<div class="row-fluid">
  <div id="footer" class="span12"> 2016 &copy; <a href="http://themedesigner.in/">guangzhoushuntian information technology</a> </div>
</div>
<!--end-Footer-part-->



</body>
</html>
